<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>物资与组织关系新增页面</title>
    <%@ include file="../../common/jsp/header.jsp"%>
    <link href="${path }/static/css/plugins/file-input/fileinput.min.css" rel="stylesheet">
    <link rel="stylesheet" href="<%=path%>static/css/plugins/ztree/zTreeStyle/zTreeStyle.css">
    <script type="text/javascript" src="<%=path%>static/js/plugins/ztree/jquery.ztree.core-3.5.js"></script>
</head>
<script language="JavaScript">

    $(function () {
        var setting = {
            view: {
                dblClickExpand: false
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                beforeClick: beforeClick,
                onClick: onClick
            }
        };

        $.post(root+'group/queryAllOrg.do',function (zNodes) {
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        },'json')

        $.post(root+'relation/queryGam.do',function (data) {
             console.log(data);
            if(data){
                var gamName =[];
                gamName.push('<option value="'+0+'">'+'请选择'+'</option>')
                for(var i=0,len=data.length;i<len;i++){
                    var gamdata = data[i];
                    //拼接成多个<option><option/>
                    gamName.push('<option id="'+gamdata.id+'" value="'+gamdata.id+'">'+gamdata.name+'</option>')
                }
                $("#wuzi").html(gamName.join(''));    //根据parkID(根据你自己的ID写)填充到select标签中
            }
        },'json')

        $("#wuzi").change(function(){
           // alert($(this).find("option:checked").attr("id"));
            var s=$(this).find("option:checked").attr("id")
            $("#gam").val(s);
        });
    })





    function beforeClick(treeId, treeNode) {
        // var check = (treeNode && !treeNode.isParent);
        // if (!check) alert("不能选择文件夹选项");
        // return check;
    }

    function onClick(e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
            nodes = zTree.getSelectedNodes(),
            v = "";
        id = "";
        nodes.sort(function compare(a,b){return a.id-b.id;});
        for (var i=0, l=nodes.length; i<l; i++) {
            v += nodes[i].name + ",";
            id += nodes[i].id + ",";
        }
        if (v.length > 0 ) v = v.substring(0, v.length-1);
        if (id.length > 0 ) id = id.substring(0, id.length-1);
        var nameObj = $("#nodeName");
        nameObj.attr("value", v);
        $("#groupPid").val(id);

            var postData = {
                groupPid : $("#groupPid").val()
            }
            $.ajax({
                url : root + "relation/queryGroup.do",
                dataType : "json",
               // async : true,
                type : "post",
                data : postData,
                success:function (result) {
                       console.log(result);
                    var obj=result[0]
                    console.log(obj);
                        $("#groupName").val(obj.name);
                }
            })
    }
    function showMenu() {
        var cityObj = $("#nodeName");
        var cityOffset = $("#nodeName").offset();
        $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    }
    function hideMenu() {
        $("#menuContent").fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    function onBodyDown(event) {
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
            hideMenu();
        }
    }
    //打开隐藏表单
    function openwindow(){
        $("#myModalLabel").text("选择组织");
        $('#myModal').modal();
    }
    //新增数据
    function saveRelation() {

    }
</script>
<body>
<input type="hidden1" name="gamId" id="gam" value="">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">选择组织</h4>
                <input type="hidden1" name="supplierId" id="groupPid" value="" >

            </div>
            <div class="modal-body">
                <div >
                    <label  for="">组织</label>
                    <input type="text" class="form-control" id="nodeName2"  name="nodeName2" placeholder="点击请选择">
                    <a id="menuBtn" href="#" onclick="showMenu(); return false;">选择</a>
                    <div id="menuContent" class="menuContent " style="display:none;">
                        <ul id="treeDemo" class="ztree" style="margin-top:0; width:160px;"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
            <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>确定</button>
        </div>
    </div>
</div>
</div>



<div class="wrapper wrapper-content animated fadeInRight">
    <div>
        <div class="col-sm-4"><input type="button" value="返回上一页" class="btn btn-success" onclick="javascript:history.back();"/></div>
    </div>
    <div class="ibox float-e-margins">
        <form class="form-inline" action=""${path }/relation/create.do"">
            <fieldset>
                <legend>新增关系(必填)</legend>
            <div class="form-group col-md-4">
                <label  for="">组织</label>
                <input type="text" class="form-control" id="nodeName"  name="nodeName" placeholder="点击请选择">
                <a href="#" class="glyphicon glyphicon-search" role="button" onclick="openwindow()"></a>
            </div>
            <div class="form-group col-md-4">
                <label for="">供应商</label>
                <input type="text" class="form-control" id="groupName"  name="groupName" placeholder="点击请选择">
                <a href="#" class="glyphicon glyphicon-search" role="button"></a>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label for="wuzi" class="control-label mglf5" style="font-size:15px;">物资:</label>
                    <select class="form-control mglf3" id="wuzi" name="wuzi" style="width:160px;"></select>

                </div>
            </div>
            </fieldset>
            <p>&nbsp</p>
            <fieldset>
            <legend>新增关系(非必填)</legend>
            <div class="form-group col-md-4">
                <label for="">税率</label>
                <input type="text" class="form-control" id="gamShuilv"  name="gamShuilv" placeholder="点击请选择">
                <a href="#" class="glyphicon glyphicon-search" role="button"></a>
            </div>
            <div class="form-group col-md-4">
                <label for="">收货组织</label>
                <input type="text" class="form-control" id="supplierYangChu"  name="supplierYangChu" placeholder="点击请选择" value="央厨收货组织">
                <a href="#" class="glyphicon glyphicon-search" role="button"></a>
            </div>
            </fieldset>
            <p>&nbsp</p>
            <fieldset>
                <div class="form-group col-md-6 col-md-offset-5">
                <button type="button" class="btn btn-info" onclick="saveRelation()">保存</button>
                </div>
            </fieldset>
        </form>
    </div>
</div>
</body>
<script type="text/javascript" src="${path }/static/js/plugins/file-input/fileinput.min.js"></script>
</html>